﻿using System;
using System.IO;
using System.Text;
using IronPython;
using IronPython.Hosting;


namespace NetInronPython
{
    class Program
    {
        static void Main(string[] args)
        {
           // Console.WriteLine("Hello World0.0!");
            var pythonEngine = Python.CreateEngine();//(options);//创建pyhon引擎
            var Index = Directory.GetCurrentDirectory().LastIndexOf("bin");
            var strpath = Directory.GetCurrentDirectory().Remove(Index) + @"Sum\py.py";

            var pyText = Convert.ToBase64String(File.ReadAllBytes(new FileInfo(strpath).ToString())); 
            var CodeString = Encoding.UTF8.GetString(Convert.FromBase64String(pyText));
            //读取文件 方法一`
             var script = pythonEngine.CreateScriptSourceFromString(CodeString);
            //读取文件 方法二` 同样适用
           //  var script = pythonEngine.CreateScriptSourceFromFile(strpath);
            var code = script.Compile(); //编译

            var scope = pythonEngine.CreateScope();
            var excuteResult = code.Execute(scope);
            //调用py方法,不带参数
            //var _func = scope.GetVariable("TestString");
            //var CustomerData = _func();
           
            //调用py方法,带参数
            var _func = scope.GetVariable("Multiplication");
            var CustomerData = _func(2,3);

            Console.WriteLine(CustomerData);
            Console.ReadKey();
                 
            

        }
    }
}
